#include "gpio.h"
#include "interrupt.h"

extern void printf(const char *fmt, ...);

void do_irq(void) 
{
	// 1. 获取中断号   GICC_IAR[9:0]
	unsigned int irq_num;
	irq_num = GICC->IAR & 0x3FF;
	// 2. 进入到中断处理程序
	switch(irq_num) {
        case EXTI5_ID:  		
			printf("huo yan chuan gan qi\n");
            hal_clear_exti_IT(EXTI_RISING,EXTI5_INPUT_EVENT);
            hal_clear_gicc_IT(EXTI5_ID);
			break;
		case 97:
			break;
		case 98:
			break;
		case EXTI9_ID:  // 99号中断处理程序
			// 3. 调用99号中断处理程序   让LED1交替闪烁/或者使用printf打印函数
			printf("key1 interrupt\n");
            // 4. 清除EXTI层中断挂起标志位   EXTI_FPR1[9] = 0x1
            hal_clear_exti_IT(EXTI_FALLING,EXTI9_INPUT_EVENT);
			// 5. 清除GICD层中断挂起标志位   GICD_ICPENDR3[3] = 0x1 
            hal_clear_gicc_IT(EXTI9_ID);
			break;
        case EXTI12_ID:  
			printf("ren ti hong wai\n");
            hal_clear_exti_IT(EXTI_RISING,EXTI12_INPUT_EVENT);
            hal_clear_gicc_IT(EXTI12_ID);
			break;
        case EXTI15_ID:  
			printf("guang dian kai guan\n");
            hal_clear_exti_IT(EXTI_RISING,EXTI15_INPUT_EVENT);
            hal_clear_gicc_IT(EXTI15_ID);
			break;
		case 100:
			break;
	}
	// 6. 清除GICC层的中断号  GICC_EOIR
	GICC->EOIR = irq_num;
}
